<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('开课审核列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <p>开课名称：</p>
                                <input type="text" name="kaikeName"/>
                            </li>
                            <li>
                                <p>学期：</p>
                                <!--                                <input type="text" name="courseName"/>-->
                                <!--<select name="stuTerm" class="form-control m-b" th:with="type=${@dict.getType('sys_period')}">
                                    <option value="0">全部学期</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>-->
                                <select th:with="terms=${@term.selectTbTermList()}" name="stuTerm" class="form-control m-b" style="height:34px;">
                                    <option value="">全部学期</option>
                                    <option th:each="term : ${terms}" th:value="${term.id}" th:text="${term.schoolYear +'学年  第'+term.term+'学期'+' (' + #dates.format(term.startTime, 'yyyy-MM-dd') + '&#45;&#45;' + #dates.format(term.endTime, 'yyyy-MM-dd')+') '}"></option>
                                </select>
                            </li>
                            <li>
                                <p>开课教师：</p>
                                <input type="text" name="courseTeacher"/>
                            </li>
                            <!--<li class="select-time">
                                <p>上课时间：</p>
                                <input type="text" class="time-input" id="startTime" placeholder="开始时间" name="params[beginCourseTime]"/>
                                <span>-</span>
                                <input type="text" class="time-input" id="endTime" placeholder="结束时间" name="params[endCourseTime]"/>
                            </li>-->
                            <li>
                                <p>开课：</p>
                                <!--                                <input type="text" name="courseAddress"/>-->
                                <select name="kaikeStatus">
                                    <option value="">全部课程</option>
                                    <option value="0">未开课</option>
                                    <option value="1">已开课</option>
                                </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('website:kaikecheck:edit')}]];
        var removeFlag = [[${@permission.hasPermi('website:kaikecheck:remove')}]];
        var prefix = ctx + "website/kaikecheck";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "开课审核",
                columns: [{
                    checkbox: true
                },
                {
                    field : 'id',
                    title : '序号',
                    visible: true,
                    formatter: function (value, row, index) {
                        return $.table.serialNumber(index);
                    }
                },
                {
                    field : 'kaikeName',
                    title : '开课名称'
                },
                {
                    field : 'courseName', 
                    title : '课程名称'
                },
                {
                    field : 'courseTeacher', 
                    title : '课程教师'
                },
                {
                    field : 'stutargetnumber',
                    title : '目标选修人数',
                    formatter: function (value, row, index) {
                        if(row.stulownumber!=null && row.stumaxnumber!=null){
                            return value=row.stulownumber+"-"+row.stumaxnumber;
                        }
                    }
                },
                {
                    field : 'realNumber',
                    title : '实际选修人数',
                    formatter:function (value,row,index) {
                        if(value==null || value==''){
                            return 0;
                        }else{
                            return value;
                        }
                    }
                },
                {
                    field : 'fabuState',
                    title : '发布状态',
                    formatter: function (value, row, index) {
                        if(value=="1"){
                            return value="<a class=\"btn btn-success btn-xs\" href=\"javascript:void(0)\"><i class=\"fa\"></i>已发布</a>";
                        }
                    }
                },
                {
                    field : 'kaikeState', 
                    title : '开课状态',
                    formatter: function (value, row, index) {
                        if(value=="0"){
                            return value="<a class=\"btn btn-danger btn-xs\" href=\"javascript:void(0)\"><i class=\"fa\"></i>未开课</a>";
                        }else{
                            return value="<a class=\"btn btn-primary btn-xs\" href=\"javascript:void(0)\"><i class=\"fa\"></i>已开课</a>";
                        }
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="fabu(\'' + row.id + '\')"><i class="fa fa-edit"></i>取消发布</a> ');
                        if(row.kaikeState =="0"){
                            actions.push('<a class="btn btn-success btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="kaike(\'' + row.id + '\')"><i class="fa fa-save"></i>开课</a>');
                        }else if(row.kaikeState =="1"){
                            actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="cnacleKaike(\'' + row.id + '\')"><i class="fa fa-remove"></i>取消开课</a>');
                        }
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });
        function fabu(id){
           /* var loginName = $.table.selectColumns("loginName");
            alert(loginName);
            return false;*/
            $.modal.confirm("确认要取消发布吗?", function() {
                $.ajax({
                    type: 'post',
                    dataType: 'json',
                    url: prefix + "/cancelFabu",
                    data: {
                        id:id,
                    },
                    cache: false,
                    async: true,
                    success: function (data) {
                        $.modal.alertSuccess("取消成功");
                        $.table.refresh();
                    }
                });
            });
        }

        function kaike(id){
            /* var loginName = $.table.selectColumns("loginName");
             alert(loginName);
             return false;*/
            $.modal.confirm("确认要开课吗?", function() {
                $.ajax({
                    type: 'post',
                    dataType: 'json',
                    url: prefix + "/kaike",
                    data: {
                        id:id,
                    },
                    cache: false,
                    async: true,
                    success: function (data) {
                        $.modal.alertSuccess("开课成功");
                        $.table.refresh();
                    }
                });
            });
        }

        function cnacleKaike(id){
            /* var loginName = $.table.selectColumns("loginName");
             alert(loginName);
             return false;*/
            $.modal.confirm("确认要取消开课吗?", function() {
                $.ajax({
                    type: 'post',
                    dataType: 'json',
                    url: prefix + "/cancleKaike",
                    data: {
                        id:id,
                    },
                    cache: false,
                    async: true,
                    success: function (data) {
                        $.modal.alertSuccess("取消成功");
                        $.table.refresh();
                    }
                });
            });
        }
    </script>
</body>
</html>